<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>axios 发送 AJAX请求</title>
</head>

<body>
  <button>GET</button>
  <button>POST</button>
  <button>AJAX</button>

  <script crossorigin="anonymous" src="https://cdn.bootcdn.net/ajax/libs/axios/0.24.0/axios.js"></script>
  <script>
    let btns = document.querySelectorAll('button');

    btns[0].onclick = function () {
      // GET请求
      // axios.get('http://127.0.0.1:8000/Axios-delay', {
      //   // url参数
      //   params: {
      //     id: 555,
      //     name: 'zzz'
      //   },
      //   // 头信息
      //   headers: {
      //     name: 'atguigu',
      //     age: 20
      //   }
      // })

      axios({
        method: 'get',
        baseURL: 'http://127.0.0.1:8000',
        url: 'Axios-delay',
        params: {
          a: 100,
          b: 200
        }
      })
        .then(function (response) {
          console.log(response);
        })
    }

    btns[1].onclick = function () {
      axios({
        method: 'post',
        baseURL: 'http://127.0.0.1:8000',
        url: '/Axios-delay',
        data: {
          firstName: 'niko',
          lastName: 'kennys'
        }
      }).then(function (response) {
        console.log(response);
      })
    }
  </script>
</body>

</html>
